Step 12: Packaging Debug and Release

您所在的位置:网站首页 cmake编译release linux Step 12: Packaging Debug and Release

Step 12: Packaging Debug and Release

2024-07-11 00:06| 来源: 网络整理| 查看: 265

Step 12: Packaging Debug and Release露

Note: This example is valid for single-configuration generators and will not work for multi-configuration generators (e.g. Visual Studio).

By default, CMake's model is that a build directory only contains a single configuration, be it Debug, Release, MinSizeRel, or RelWithDebInfo. It is possible, however, to setup CPack to bundle multiple build directories and construct a package that contains multiple configurations of the same project.

First, we want to ensure that the debug and release builds use different names for the libraries that will be installed. Let's use d as the postfix for the debug libraries.

Set CMAKE_DEBUG_POSTFIX near the beginning of the top-level CMakeLists.txt file:

CMakeLists.txt露 set(CMAKE_DEBUG_POSTFIX d) add_library(tutorial_compiler_flags INTERFACE)

And the DEBUG_POSTFIX property on the tutorial executable:

CMakeLists.txt露 add_executable(Tutorial tutorial.cxx) set_target_properties(Tutorial PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) target_link_libraries(Tutorial PUBLIC MathFunctions tutorial_compiler_flags)

Let's also add version numbering to the MathFunctions library. In MathFunctions/CMakeLists.txt, set the VERSION and SOVERSION properties:

MathFunctions/CMakeLists.txt露 set_property(TARGET MathFunctions PROPERTY VERSION "1.0.0") set_property(TARGET MathFunctions PROPERTY SOVERSION "1")

From the Step12 directory, create debug and release subdirectories. The layout will look like:

- Step12 - debug - release

Now we need to setup debug and release builds. We can use CMAKE_BUILD_TYPE to set the configuration type:

cd debug cmake -DCMAKE_BUILD_TYPE=Debug .. cmake --build . cd ../release cmake -DCMAKE_BUILD_TYPE=Release .. cmake --build .

Now that both the debug and release builds are complete, we can use a custom configuration file to package both builds into a single release. In the Step12 directory, create a file called MultiCPackConfig.cmake. In this file, first include the default configuration file that was created by the cmake executable.

Next, use the CPACK_INSTALL_CMAKE_PROJECTS variable to specify which projects to install. In this case, we want to install both debug and release.

MultiCPackConfig.cmake露 include("release/CPackConfig.cmake") set(CPACK_INSTALL_CMAKE_PROJECTS "debug;Tutorial;ALL;/" "release;Tutorial;ALL;/" )

From the Step12 directory, run cpack specifying our custom configuration file with the config option:

cpack --config MultiCPackConfig.cmake


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3